import { Node } from "cc";
import { IGameLogic, IGameSystem } from "./interface/ecsEnterface";

export class GameLogic implements IGameLogic{
    private _owner:IGameSystem
    private _node:Node;
    get node(): Node {return this._node}
    get owner(): IGameSystem {return this._owner;};

    get NAME(): string {
        throw new Error("Method not implemented.");
    }
    execute(...params: any) {
        //throw new Error("Method not implemented.");
    }
    onDestroy() {
        //throw new Error("Method not implemented.");
    }
    init(){
        //throw new Error("Method not implemented."); 
    }
    update(dt:number){
        
    }
    lateUpdate(dt: number){
       
    }
     /**
     * websocket 请求
     * @param msg       请求消息
     * @param data      请求数据
     * @param callback  请求完成回调
     * 
     */
    send(msg:string,data:any,callback?:()=>void){
        this.owner.send(msg,data,callback)
    }
    /**
     * http请
     * @param path  url 请求地址
     * @param data  请求数据
     * @param type  请求类型
     * 
     */
    request(path:string,data:any,type?:string):Promise<any>{
        return this.owner.request(path,data,type)
    }

     /**
     * 添加消息监听
     * @param msg 
     * @param callFun 
     * @param caller 
     */
     addMsg(msg:string,callFun:any,caller:any){
        this.owner.addMsg(msg,callFun,caller)
    }
    /**
     * 发送消息
     * @param msg 
     * @param params 
     */
    sendMsg(msg:string,...params:any){
        this.owner.sendMsg(msg,...params)
    }
    /**
     * 删除消息监听
     * @param msg 
     * @param callFun 
     * @param caller 
     */
    removeMsg(msg:string,callFun:any,caller:any){
        this.owner.removeMsg(msg,callFun,caller)
    }
    /**
     * 删除当前组消息
     * @param group 
     */
    removeGroup(){
        this.owner.removeGroup()
    }
    /** 将消息添加到全局消息模块中 */
    addWorld(msg:string,callFun:any,caller:any){this.owner.addWorld(msg,callFun,caller)}
    /** 发送全局消息 */
    sendWorld(msg:string,...params){this.owner.sendWorld(msg,...params)}
    /** 删除全局消息监听 */
    removeWorld(msg:string,callFun:any,caller:any){this.owner.removeWorld(msg,callFun,caller)}
    
}